package com.cpj.bsyyzx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.cpj.bsyyzx.entity.Role;
import com.cpj.bsyyzx.mapper.RoleMapper;
import com.cpj.bsyyzx.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 五个臭皮匠
 * @since 2021-05-09
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    @Override
    public Object list(Role role) {
        QueryWrapper<Role> wrapper = new QueryWrapper<>();
        if(StringUtils.isNotBlank(role.getRoleName())) {
            wrapper.like("role_name",role.getRoleName());
        }
        return this.list(wrapper);
    }

    @Override
    public boolean add(Role role) {
        QueryWrapper<Role> wrapper = new QueryWrapper<>();
        wrapper.eq("role_name",role.getRoleName());
        Role role1 = this.getOne(wrapper);
        if(role1 == null )
            return this.save(role);
        return false;
    }
}
